#include "Thread.h"

using namespace DataShare;

std::vector<std::thread> Thread::threads;

Thread::Thread() : isRunning(false) {}

Thread::~Thread() {}

void Thread::Start() {
    for (;;) {
        if (this->Init() == ErrorInfo::OK) {
            break;
        }
    }

    thread    = std::thread(&Thread::Run, this);
    isRunning = true;

    threads.push_back(std::move(thread));
}

void Thread::Join() {
    this->thread.join();
    isRunning = false;
}

void Thread::JoinAll() {
    std::vector<std::thread>::iterator iter;
    for (iter = threads.begin(); iter != threads.end(); iter++) {
        iter->join();
    }
}
